﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _07_Panel_嵌入式窗体
{
    public partial class BaseForm : Form
    {
        /// <summary>
        /// 窗体图标
        /// </summary>
        [Description("窗体图标")]
        public Image FormIcon
        {
            get { return this.pictureBox4.Image; }
            set { this.pictureBox4.Image = value; }
        }

        /// <summary>
        /// 标题文本
        /// </summary>
        [Description("窗体的标题文本")]
        public string Title
        {
            get { return this.lbl_TitleName.Text; }
            set { this.lbl_TitleName.Text = value; }
        }

        public BaseForm()
        {
            InitializeComponent();
            //设置窗体的工作区域为屏幕的工作区域
            this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;
        }
        /// <summary>
        /// 关闭窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 鼠标进入关闭按钮时，显示红色背景
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            this.pictureBox1.BackColor = Color.Red;
        }
        /// <summary>
        /// 鼠标离开关闭按钮时，显示SeaGreen背景
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            this.pictureBox1.BackColor = Color.SeaGreen;
        }
        /// <summary>
        /// 最大化/正常大小-窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            //判断当前窗体是否是最大化状态
            if (this.WindowState == FormWindowState.Maximized)
            {
                //如果是最大化状态，那么将窗体设置为正常大小
                this.WindowState = FormWindowState.Normal;
                this.pictureBox2.Image = Properties.Resources.最大化;
            }
            else
            {
                //如果不是最大化状态，那么将窗体设置为最大化
                this.WindowState = FormWindowState.Maximized;
                this.pictureBox2.Image = global::_07_Panel_嵌入式窗体.Properties.Resources.最小化;
            }
        }
        /// <summary>
        /// 最小化窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox3_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        //记录鼠标按下的坐标
        int OldX;
        int OldY;

        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            //判断是否是鼠标左键按下，如果是则记录鼠标按下的坐标
            if (e.Button == MouseButtons.Left)
            {
                //记录鼠标按下的坐标
                OldX = e.X;
                OldY = e.Y;
            }

        }
        /// <summary>
        /// 鼠标移动时，移动窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
            //判断是否是鼠标左键按下，根据相对的位置移动窗体
            if (e.Button == MouseButtons.Left)
            {
                //移动窗体
                this.Left += e.X - OldX;
                this.Top += e.Y - OldY;
            }
        }
    }
}
